package org.mayuanxiaonong.timservice.dao.impl;

import org.mayuanxiaonong.timservice.dao.UserDao;
import org.mayuanxiaonong.timservice.pojo.Presence;
import org.mayuanxiaonong.timservice.pojo.User;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

public class UserDaoMongo extends BaseDaoMongo implements UserDao {

	@Override
	public User getUser(Integer uid) {
		return getMongoTemplate().findOne(
				new Query(Criteria.where("uid").is(uid)), User.class,
				USER_COLLECTION);
	}

	@Override
	public void savePresence(Presence presence) {
		getMongoTemplate().remove(
				new Query(Criteria.where("uid").is(presence.getUid())),
				PRESENCE_COLLECTION);
		getMongoTemplate().save(presence, PRESENCE_COLLECTION);
	}

}
